package com.copsoftware.comun.services;

import java.util.Collection;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.copsoftware.comun.beans.PersonaFlt;
import com.copsoftware.comun.dao.PersonaDAO;
import com.copsoftware.comun.interfaces.IPersona;
import com.copsoftware.hibernate.cfg.HibernateUtils;
import com.copsoftware.mantenimientos.persona.beans.PersonaCompletaFlt;

public class PersonaService {

	public IPersona buscarPersona(PersonaFlt personaFlt) {

		Session session = HibernateUtils.getSessionFactory()
				.getCurrentSession();
		Transaction tx = null;
		IPersona persona = null;
		try {
			tx = session.beginTransaction();
			PersonaDAO personaDAO = new PersonaDAO();
			personaDAO.setSession(session);
			persona = personaDAO.buscarPersona(personaFlt);
			tx.commit();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			tx.rollback();
		}

		return persona;

	}

	public static void main(String[] args) {
		PersonaFlt personaFlt = new PersonaFlt();
		personaFlt.setNombre("1");
		PersonaService personaService = new PersonaService();
		personaService.buscarPersona(personaFlt);
	}

	public Collection buscarPersona(PersonaCompletaFlt personaCompletaFlt) {
		Session session = HibernateUtils.getSessionFactory()
				.getCurrentSession();
		Transaction tx = null;
		Collection listaPersonas= null;
		try {
			tx = session.beginTransaction();
			PersonaDAO personaDAO = new PersonaDAO();
			personaDAO.setSession(session);
			listaPersonas = personaDAO.buscarPersona(personaCompletaFlt);
			tx.commit();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			tx.rollback();
		}

		return listaPersonas;

	}

}
